package com.qjz.diancan.controller;


import com.qjz.diancan.model.dto.LoginDto;
import com.qjz.diancan.model.entity.User;
import com.qjz.diancan.model.vo.common.Result;
import com.qjz.diancan.model.vo.common.ResultCodeEnum;
import com.qjz.diancan.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Tag(name = "用户接口")
@RestController
@RequestMapping(value = "/auth")
public class loginController {

    @Autowired
    private UserService userService;

    @Operation(summary = "登录接口")
    @PostMapping(value = "/login")
    public Result login(@RequestBody LoginDto loginDto)
    {
        Map<String, Object> token = userService.login(loginDto);
        return Result.build(token, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "注册接口")
    @PostMapping(value = "/register")
    public Result register(@RequestBody User user)
    {
        userService.register(user);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
